package com.sky.controller.admin;

import cn.hutool.core.lang.UUID;
import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 通用接口
 *
 * @Author mr.li
 * @Date 2025/7/8 11:11
 */
@RestController
@Slf4j
@Api(tags = "通用接口")
@RequestMapping("/admin/common")
public class CommonController {
    @Autowired
    private AliOssUtil aliOssUtil;


    @PostMapping("/upload")
    public Result<String> upload(@RequestBody MultipartFile  file) throws IOException {

        byte[] bytes = file.getBytes();

        //上传到阿里云中的文件名字
        String originalFilename = file.getOriginalFilename();//获取源文件名


        String s = UUID.randomUUID().toString();
        String objectName = s+"_"+originalFilename;


        String fileLoad = aliOssUtil.upload(bytes, objectName);


        return Result.success(fileLoad);

    }

}
